package com.itheima.server.controller;


import com.itheima.common.core.controller.BaseController;
import com.itheima.common.core.domain.AjaxResult;
import com.itheima.common.core.domain.AjaxResult;
import com.itheima.common.core.domain.R;
import com.itheima.common.core.page.TableDataInfo;
import com.itheima.server.domain.Activite;
import com.itheima.server.dto.ActiReportQueryDto;
import com.itheima.server.dto.ContractStatisticsDto;
import com.itheima.server.dto.PageDto;
import com.itheima.server.service.ReportService;
import com.itheima.server.vo.ActiReportQueryVO;
import com.itheima.server.vo.DeptContractReportVo;
import com.itheima.server.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import com.itheima.common.core.controller.BaseController;
import com.itheima.common.core.page.TableDataInfo;
import com.itheima.server.dto.ReportClueDto;
import com.itheima.server.service.ReportService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Map;

@RestController
@RequestMapping("/report")
@Slf4j
public class ReportController extends BaseController {
    @Autowired
    private ReportService reportService;






    /**
     * 线索统计列表
     * @param dto
     * @return
     */
    @GetMapping("/cluesStatisticsList")
    public TableDataInfo cluesStatisticsList(ReportClueDto dto){
        List<ReportClueVo> list = reportService.reportClueList(dto);
        return getDataTable(list);

    }


    /**
     * 渠道统计 列表
     * @param dto
     * @return
     */
    @GetMapping("/activityStatisticsList")
    public TableDataInfo activityStatisticsList(ActiReportQueryDto dto){
        List<ActiReportQueryVO> list = reportService.activityStatisticsList(dto);
        return getDataTable(list);
    }

    /**
     * 渠道统计 图表1
     * @return
     */
    @GetMapping("/chanelStatistics/{beginTime}/{endTime}")
    public List<Map<String, Object>> chanelStatistics(
            @PathVariable String beginTime,
            @PathVariable String endTime
    ){
        List<Map<String, Object>> list = reportService.chanelStatistics(beginTime, endTime);
        return  list;
    }

    /**
     * 获取部门合同数和成交金额表
     * @param dto
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/deptStatisticsList/{start}/{end}")
    public TableDataInfo deptStatisticsList(PageDto dto, @PathVariable String start, @PathVariable String end){
     List<DeptContractReportVo> list=  reportService.getdeptStatisticsList(dto,start,end);
     return getDataTable(list);
    }

    /**
     * 渠道统计 图表2
     * @return
     */
    @GetMapping("/activityStatistics/{beginTime}/{endTime}")
    public List<Map<String, Object>> activityStatistics(
            @PathVariable String beginTime,
            @PathVariable String endTime
    ){
        List<Map<String, Object>> list = reportService.activityStatistics(beginTime, endTime);
        return  list;
    }




    @GetMapping("/cluesStatistics/{begin}/{end}")
    public ReportClueChartVo getClueChart(@DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable Date begin
                                         ,@DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable Date end){
        log.info("开始时间：{},结束时间：{}",begin,end);

        return reportService.getClueChart(begin,end);

    }

    @GetMapping("/getVulnerabilityMap/{begin}/{end}")
    public R getVulnerabilityMap(@DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable Date begin
                                     , @DateTimeFormat(pattern = "yyyy-MM-dd")@PathVariable Date end){
        log.info("开始时间：{},结束时间：{}",begin,end);

        VulnerabilityMapVo vulnerabilityMapVo = reportService.getVulnerabilityMap(begin,end);
        return R.ok(vulnerabilityMapVo);
    }




    /**
     * 合同统计列表
     * @param dto
     * @return
     */
    @GetMapping("/contractStatisticsList")
    public AjaxResult getContractStatisticsList(ContractStatisticsDto dto){
        AjaxResult ajaxResult = reportService.getContractStatisticsList(dto);
        return ajaxResult;
    }
    @GetMapping("/salesStatistics/{begin}/{end}")
    public SalesStatisticsVo getSalesStatistics(@PathVariable String begin, @PathVariable String end){
        log.info("开始时间：{},结束时间：{}",begin,end);

        SalesStatisticsVo salesStatisticsVo = reportService.getSalesStatistics(begin,end);
        return salesStatisticsVo;
    }

    /**
     * 客户新增统计
     * @param
     * @return
     */
    @GetMapping("/contractStatistics/{begin}/{end}")
    public CustVo getPairdDataNewAndOldClue(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") Date begin,
                                                           @PathVariable  @DateTimeFormat(pattern = "yyyy-MM-dd") Date end ){
        log.info("开始统计客户人数 时间段：{},结束时间：{}",begin,end);
        return reportService.getPairdDataNewAndOldClue(begin,end);
    }


    /**
     * 学科统计
     * @return
     */
    @GetMapping("/subjectStatistics/{begin}/{end}")
    public List<SubjectStatisticsVo> getSubjectStatistics(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") Date begin,
                                     @PathVariable  @DateTimeFormat(pattern = "yyyy-MM-dd") Date end){
        List<SubjectStatisticsVo> list = reportService.getSubjectStatistics(begin,end);
        return list;
    }

    /**
     * 获取渠道合同数和成交金额表
     * @param dto
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/channelStatisticsList/{start}/{end}")
    public TableDataInfo getChannelStatisticsList(PageDto dto, @PathVariable String start, @PathVariable String end){
        List<ChannelContractReportVo> list=  reportService.getChannelStatisticsList(dto,start,end);
        return getDataTable(list);
    }


    /**
     * 获取归属人合同数和成交金额表
     * @param dto
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/ownerShipStatisticsList/{start}/{end}")
    public TableDataInfo getOwnerStatisticsList(PageDto dto, @PathVariable String start, @PathVariable String end){
        List<OwnerShipContractReprtVo> list=  reportService.getOwnerStatisticsList(dto,start,end);
        return getDataTable(list);
    }





}
